package converter; 

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import to.Determinacao;
import DAO.DeterminacaoDAO;

@FacesConverter(value = "determinacaoConverter")
public class ConverterDeterminacao implements Converter {
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		DeterminacaoDAO dDAO = new DeterminacaoDAO();
		Determinacao determinacao = null;
		if ((value != null) && (!value.equals(""))) {
			determinacao = (Determinacao) dDAO.buscarPorCodigo(Integer.parseInt(value));
		}
		return determinacao;
	}

	public String getAsString(FacesContext context, UIComponent component,
			Object value) {
		Long retorno = null;
		if (!(value == null)) {
			Determinacao determinacao = new Determinacao();
			determinacao = (Determinacao) value;
			retorno = (long) determinacao.getCodigo();
		}
		return retorno.toString();
	}
}
